package com.bd.framework.utils.database;

import java.sql.Connection;
import java.util.Map;

import com.bd.framework.pojo.IniInfo;
import com.bd.framework.utils.IniConfig;

/**
 * @author hnxdyl@hotmail.com
 * 校验数据库连接信息,根据ini文件中的offLine确定是否连接远程数据库
 * offLine = 0远程,offLine =1本地
 * */
public class CheckConnection {
	
	public Connection getCheckConnection(){
		Connection dbConnection = null;
		IniConfig iniConfig = new IniConfig();
		Map<String, Object> map = iniConfig.getIniInfo();
		if (map.get("error") == null || map.get("error").equals(null)) {
			IniInfo iniInfo = (IniInfo) map.get("success");
			// offLine未0且和远程数据库网络正常,则返回远程数据库连接,否则返回本地数据库连接
			if(iniInfo.getOffLine().equals("0") || iniInfo.getOffLine() == "0"){
				dbConnection = ConnectionFactory.getConnectionBASEDB();
				if(dbConnection == null){
					dbConnection =SQliteConnection.getSQliteConnection().getSQLiteCon();
				}
			}else{
				dbConnection = SQliteConnection.getSQliteConnection().getSQLiteCon();
			}
		} 
		return dbConnection;
	}
	
	public static void main(String[] args){
		System.out.println(new CheckConnection().getCheckConnection().getClass());
	}
}
